//
//  SECViewController.m
//  7.14详情
//
//  Created by lovena on 15/7/15.
//  Copyright (c) 2015年 lovena. All rights reserved.
//

#import "SECViewController.h"
#import "PJCell.h"
#import "XQCellModel.h"
#import "MJExtension.h"
#import "TWscrollView.h"
#import "XQViewController.h"
@interface SECViewController ()
@property(nonatomic,strong)UIButton *selectedBtn;//已选中按钮
@property(nonatomic,assign)CGFloat height;
@property(nonatomic,retain)TWscrollView *scrollView;
@end

@implementation SECViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    //加载滑动
    [self loadScroll];
    self.navigationItem.title=@"商品详情";
    
    //self.edgesForExtendedLayout=UIRectEdgeNone;
    //左边按钮
    UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
    [btn setBackgroundImage:[UIImage imageNamed:@"back_black_icon"] forState:UIControlStateNormal];
    btn.frame=CGRectMake(0, 0, 25, 20);
    [btn addTarget:self action:@selector(returnBtn) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *left=[[UIBarButtonItem alloc]initWithCustomView:btn];
    self.navigationItem.leftBarButtonItem=left;
//    XQViewController *con = (XQViewController*)self.navigationController;
//    [con NaviewHiddenOrShow:YES];
//    NSLog(@"%@",NSStringFromCGRect(con.QXnaView.frame) );

}
//返回
-(void)returnBtn
{
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)viewWillAppear:(BOOL)animated
{
      [self clickBtn:_firstBtn];
}
- (IBAction)clickBtn:(UIButton *)sender {
    if (_selectedBtn!=sender) {
        _selectedBtn.selected=NO;
        [_selectedBtn setFont:[UIFont systemFontOfSize:14]];
        sender.selected=YES;
        [sender setFont:[UIFont systemFontOfSize:15]];
        _selectedBtn=sender;
    }
    //移动背景
    //x
    CGRect rect=self.activeView.frame;
    rect.origin.x=_selectedBtn.frame.origin.x;
    self.activeView.frame=rect;
    
    if(sender.tag==0)
    {
        [self loadScroll];
        [self.view bringSubviewToFront:_scrollView];
    }
    else if (sender.tag==1)
    {
        
    }
    else
    {
        
        [self.view bringSubviewToFront:_tableView];
        
    }
    
}

//加载滑动
-(void)loadScroll
{
    _scrollView=[[TWscrollView alloc]initWithFrame:CGRectMake(0, 105, 320, self.view.frame.size.height-64)];
    [self.view addSubview: _scrollView];
}
//数据加载
-(NSArray *)pjArray
{
    if(_pjArray==nil)
    {
        _pjArray=[NSArray array];
        _pjArray=[XQCellModel modelArrayWithFilename:@"pj.plist"];
    }
    return _pjArray;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.pjArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *ID=@"cell";
    PJCell *cell=[tableView dequeueReusableCellWithIdentifier:ID];
    if (cell==nil) {
        cell=[[PJCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    cell.cmodel=self.pjArray[indexPath.row];
    //cell.backgroundColor=[UIColor clearColor];
    self.height=cell.cellHeight;
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return self.height;
}
- (IBAction)return {
    [self.navigationController popViewControllerAnimated:YES];
}
@end
